//
//  reserveHeader.m
//  SimpleHappy
//
//  Created by lanou on 15/11/26.
//  Copyright © 2015年 RockyFung. All rights reserved.
//

#import "reserveHeader.h"
#import "SDCycleScrollView.h"
#import "Define.h"
#import "PictureModel.h"
#import "DetailController.h"
#import "SHDetailModel.h"

@interface reserveHeader ()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong) NSMutableArray *picArray; // 图片数组 URLString
@property (nonatomic, strong) NSMutableArray *titleArray; // 标题数组
@end
@implementation reserveHeader
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat width = KScreenWidth - 10;
        CGFloat height = width / 640 * 330;

//        CarouselFigure *scrowView = [[CarouselFigure alloc]initWithFrame:CGRectMake(5, 0, width, height-5)];
//        scrowView.array = @[@"one",@"two",@"three"];
//        [self.contentView addSubview:scrowView];
        //网络加载 --- 创建带标题的图片轮播器
        self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(5, 5, width, height) imageURLStringsGroup:nil]; // 模拟网络延时情景
        self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        self.cycleScrollView.delegate = self;
        //        self.cycleScrollView.titlesGroup = self.titleArray; // ===========给标题数组
        self.cycleScrollView.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
        self.cycleScrollView.placeholderImage = [UIImage imageNamed:@"placeholder"];

            self.cycleScrollView.autoScroll = YES;

        [self.contentView addSubview:_cycleScrollView];

               [self.contentView addSubview:_cycleScrollView];

    }
    return self;
}

- (void)setModelArray:(NSMutableArray *)modelArray
{

    _modelArray = modelArray;

    if (modelArray.count == 1)
    {
        self.cycleScrollView.autoScroll = NO;
    }
    else
    {
        self.cycleScrollView.autoScroll = YES ;
    }

    
    if (modelArray.count <=1)
    {
        self.cycleScrollView.autoScroll = NO;
    }else{
        self.cycleScrollView.autoScroll = YES;
    }
    self.picArray = [NSMutableArray array];
    for (PictureModel *model in modelArray)
    {
        [self.picArray addObject:model.picUrl];
    }
    self.cycleScrollView.imageURLStringsGroup = self.picArray;

}

#pragma mark - SDCycleScrollViewDelegate


- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    DetailController *detailVc = [[DetailController alloc]init];
    PictureModel *model =self.modelArray[index];
    detailVc.targetUrl = model.openUrl;
    detailVc.isDiscover = YES;
       // 获取控制器
    UITableView *object = (UITableView *)[self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] && object != nil) {
        object = (UITableView *)[object nextResponder];
    }
    UIViewController *uc = (UIViewController*)object;
    
   
    
    
    SHDetailModel *SHModel = [[SHDetailModel alloc]init];
    SHModel.picUrl = model.picUrl;
    SHModel.title = @"无";
    SHModel.openUrl = model.openUrl;
    detailVc.SHDetailModel = SHModel;
    
 
    
    
    // 跳转
    detailVc.hidesBottomBarWhenPushed = YES;
    detailVc.navigationItem.rightBarButtonItems = nil;
    detailVc.isHead = YES;
    [uc.navigationController pushViewController:detailVc animated:YES];
}



@end
